#include <vector>
#include <set>
#include <iostream>
#include <unordered_map>
#include <numeric>

using namespace std;

vector<int> productExceptSelf(vector<int>& nums) {
    vector<int> ret = nums;
    if(nums.size() == 1 || nums.size() == 0){ return ret; }
    for(int i = ret.size()-1; i > 0; i--){
        ret[i-1] = ret[i] * ret[i-1];
    }
    ret.push_back(1);
    for(int j = 0; j < nums.size()-1; j++){
        nums[j+1] = nums[j+1] * nums[j]; 
    }
    ret[0] = ret[1];
    for(int r = 1; r < ret.size()-1; r++){
        ret[r] = ret[r+1] * nums[r-1];
    }
    ret.pop_back();
    return ret;
}

int main(){
    vector<int> nums = {1,2,3,4};
    vector<int> ret = productExceptSelf(nums);
    for(int i : ret){
        cout << i << endl;
    }
    return 0;
}